package com.example.blog.controller;

import com.example.blog.service.TagService;
import com.example.blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tags")
public class TagsController {
    @Autowired
    private TagService tagService;

    /**
     * 在首页查询所有文章标签
     *
     * @return
     */
    @GetMapping
    public Result findAll() {
        return tagService.findAll();
    }

    @GetMapping("/hot")
    public Result hot() {
        Long limit = 6L;//查询最热门的6个标签
        return tagService.hots(limit);
    }

    /**
     * 获取文章所有标签以及对应每个标签的文章数量
     *
     * @return
     */
    @GetMapping("detail")
    public Result findAllDetail() {
        return tagService.findAllDetail();
    }

    @GetMapping("/detail/{id}")
    public Result findTagDetailById(@PathVariable("id") Long id) {
        return tagService.findTagById(id);
    }
}
